from dronekit import connect, VehicleMode
import time 

vehicle = connect('/dev/ttyACM0', wait_ready=True, baud=921600)
vehicle.mode =VehicleMode("GUIDED") 
vehicle.armed = True
print("TAKE OFF!!!")
vehicle.simple_takeoff(1)
while True: 
    print(" Altitude: ",vehicle.location.global_relative_frame.alt) 
        # 当高度上升到目标高度的0.95倍时，即认为达到了目标高度，退出循环 
        #vehicle.location.global_relative_frame.alt为相对于home点的高度 
    if vehicle.location.global_relative_frame.alt>= 1 * 0.95: 
        print("Reached targetaltitude")
#         vehicle.armed = False
        break  
    time.sleep(1)
print("AltHold 10s")
time.sleep(10)
print("Returningto Launch")
vehicle.mode = VehicleMode("LAND")
print("Closevehicle object")
vehicle.close()
    